<?php

//格式化富文本内容
function handleRichText($content)
{
    $url = 'http://' . $_SERVER['SERVER_NAME'] . '/uploads/';
    $content = htmlspecialchars_decode(str_replace('/uploads/', $url, $content));
    return str_replace('\\', '', $content);
}

//截取规定字符串内容
function cut($begin, $end, $str)
{
    $b = mb_strpos($str, $begin) + mb_strlen($begin);
    $e = mb_strpos($str, $end) - $b;

    return mb_substr($str, $b, $e);
}

//保留两位小数，四舍五入和不四舍五入
function handleDecimal($num, $rounding = true)
{
    if ($rounding) {
        return sprintf("%.2f", $num);
    } else {
        return sprintf("%.2f", substr(sprintf("%.3f", $num), 0, -2));
    }

}